<?php 
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_sys_class('base');
class index extends base{
	public $db,$setting;
	function __construct() {
		parent::__construct();
		$this->db = pc_base::load_model('news_nsr_model');
		$model_setting=pc_base::load_model('site_setting_model');
        $this->setting = $model_setting->getValue("missworldyear",get_siteid());
        //获取轮询
        $this->pollInfo();
	}

	/**
	 * 获取轮询
	 */
	public function pollInfo ()
	{
		$poll = file_get_contents(API_URL."/xinsilu/v1/polls/pollsInfo?pollsId=20&siteid=1");
		$poll= json_decode($poll,true);
		$this->poll_info = $poll['data'];
	}
	
	/**
	 * missworld首页
	 */
	public function index() {
		$temp = 'index';
		//新闻中心
		$newscatid = '117';
		$news = file_get_contents(API_URL."/xinsilu/v1/column/content/117?max=13&type=1&siteid=1");
		$news = json_decode($news,true);

		//赛事花絮
		$piccatid = '118';
		$pics = file_get_contents(API_URL."/xinsilu/v1/column/content/118?max=1&type=3&siteid=1");
		$pics = json_decode($pics,true);
		$pic = file_get_contents(API_URL.'/xinsilu/v1/pictureNsr/getPictureNsrById?id='.$pics['data']['returnList'][0]['id']);
		$pic = json_decode($pic,true);
		$picsInfo = json_decode($pic['data']['pictureurls'],true);
		//var_dump($picsInfo);die;

		//首页视频
		$videocatid = '121';
		$video = file_get_contents(API_URL."/xinsilu/v1/column/content/121?max=1&type=2&siteid=1");
		$video = json_decode($video,true);

		//历届中国小姐
		$talentcatid = '119';
		$talent = file_get_contents(API_URL."/xinsilu/v1/column/content/119?max=15&type=1&siteid=1");
		$talent = json_decode($talent,true);
		$t = array();
		foreach ($talent['data']['returnList'] as $v) {
			$num = substr($v['title'],3,2);
			$t[$num]['title'] = $v['title'];
			$t[$num]['image'] = $v['image'];
			$t[$num]['id'] = $v['id'];
			$newsInfo = $this->db->get_one(array('id'=>$v['id']),'info_brief');
			$t[$num]['description'] = $newsInfo['info_brief'];
		}
		$talentList = array();
		foreach ($this->setting as $k => $vo) {
			$talentList[$vo] = $t[$vo];
			$talentList[$vo]['year'] = $k;
		}
		include template('contest', $temp);
	}
	
	/**
	 * missworld新闻列表
	 */
	public function news() {
		$temp = "news";


		include template('contest', $temp);
	}

	/**
	 * missworld图集列表
	 */
	public function imagelist() {
		$temp = "imagelist";
		$catid = intval($_GET['catid']);
		$cate = pc_base::load_model('category_model');
		$cateInfo = $cate->get_one(array('catid'=>$catid));
		if ($cateInfo['type'] == 1) {
			$info = file_get_contents(API_URL."/xinsilu/v1/column/content/".$cateInfo['catid']."?max=1&type=1&siteid=1");
			$info = json_decode($info,true);
			$infos = file_get_contents(API_URL."/xinsilu/v1/newsNsr/getNewNsrById?id=".$info['data']['returnList'][0]['id']);
			$infos = json_decode($infos,true);
			$news = $infos['data'];
			//点击量添加
			$this->db->update(array('onclick_all'=>($news['onclickAll']+1)),array('id'=>$news['id']));
			include template('contest', 'shows');die;
		} else {
			$cateList = $cate->select(array('parentid'=>$catid));
			if (empty($cateList)) {
				$list = file_get_contents(API_URL."/xinsilu/v1/column/content/".$catid."?max=9&offset=0&type=0&siteid=1");
				$list = json_decode($list,true);
				include template('contest', 'lists');die;
			} else {
				foreach ($cateList as $k => $v) {
					$list = file_get_contents(API_URL."/xinsilu/v1/column/content/".$v['catid']."?max=6&offset=0&type=0&siteid=1");
					$list = json_decode($list,true);
					$cateList[$k]['list'] = $list['data'];
				}
				include template('contest', $temp);
			}
		}
	}

	/**
	 * missworld新闻详情
	 */
	public function show() {
		$temp = "show";
		$id = $_GET['id']?(int)$_GET['id']:'';
		$catid = $_GET['catid']?(int)$_GET['catid']:'';
		if (!$id) {
			return false;
		}

		//取资讯基本信息
		$news = $this->db->get_one(array('id'=>$id));
		$news['update_time'] = substr($news['update_time'],0,10);
		//点击量添加
		$this->db->update(array('onclick_all'=>($news['onclick_all']+1)),array('id'=>$id));
		//取栏目信息
		$type = pc_base::load_model('category_model');
		if ($catid) {
			$catInfo = $type->get_one(array('catid'=>$catid),'catname,parentid');
			if ($catInfo['parentid']) {
				if($catInfo['parentid'] != '120' && $catInfo['parentid'] != '116') {
					$parentInfo = $type->get_one(array('catid'=>$catInfo['parentid']),'catname,catid');
				}
			}
		}
		//var_dump($typeInfo);die;
		include template('contest', $temp);
	}

	/**
	 * missworld图集详情
	 */
	public function imageshow() {
		$temp = "imageshow";
		$id = $_GET['id']?(int)$_GET['id']:'';
		$catid = $_GET['catid']?(int)$_GET['catid']:'';
		if (!$id) {
			return false;
		}

		//取图集基本信息
		$picture_model = pc_base::load_model('picture_nsr_model');
		$picture = $picture_model->get_one(array('id'=>$id));
		$pictureurls = json_decode($picture['pictureurls'],true);
		$picture['update_time'] = substr($picture['update_time'],0,10);
		//取上一篇下一篇
		$source = pc_base::load_model('category_source_model');
		$where = 'source_type = 3';
		if ($catid) {
			$where .= ' and cate_id = '.$catid;
		}
		$respre = $source->get_one($where.' and source_id<'.$id, 'source_id', 'source_id desc');
		if ($respre['source_id']) {
			$pre = $picture_model->get_one(' id = '.$respre['source_id']);
		}
		$resnext = $source->get_one($where.' and source_id>'.$id, 'source_id', 'source_id asc');
		if ($resnext['source_id']){
			$next = $picture_model->get_one(' id = '.$resnext['source_id']);
		}
		
		//取栏目信息
		if ($catid) {
			$type = pc_base::load_model('category_model');
			$catInfo = $type->get_one(array('catid'=>$catid),'catname,parentid');
			if ($catInfo['parentid']) {
				if($catInfo['parentid'] != '120' && $catInfo['parentid'] != '116') {
					$parentInfo = $type->get_one(array('catid'=>$catInfo['parentid']),'catname,catid');
				}
			}
		}

		include template('contest', $temp);
	}

	/**
	 * missworld视频详情
	 */
	public function videoshow() {
		$temp = "videoshow";
		$id = $_GET['id']?(int)$_GET['id']:'';
		$catid = $_GET['catid']?(int)$_GET['catid']:'';
		if (!$id) {
			return false;
		}

		//取视频基本信息
		$video = pc_base::load_model('video_nsr_model');
		$info = $video->get_one(array('id'=>$id));

		//统计观看次数
		$video->update(array('play_times'=>($info['play_times']+1)),array('id'=>$info['id']));

		//取栏目信息
		if ($catid) {
			$type = pc_base::load_model('category_model');
			$catInfo = $type->get_one(array('catid'=>$catid),'catname,parentid');
			if ($catInfo['parentid']) {
				if($catInfo['parentid'] != '120' && $catInfo['parentid'] != '116') {
					$parentInfo = $type->get_one(array('catid'=>$catInfo['parentid']),'catname,catid');
				}
			}
		}

		include template('contest', $temp);
	}

	/**
	 * ajax获取数据列表
	 */
	public function ajaxNewsList ()
	{
		$catid = intval($_POST['catid']);
		$page = intval($_POST['page']);
		$num = intval($_POST['num']);
		$offset = ($page-1)*$num;
		$list = file_get_contents(API_URL."/xinsilu/v1/column/content/".$catid."?max=".$num."&offset=".$offset."&type=0&siteid=1");
		echo $list;die; 
	}
}
?>